﻿using AutoMapper;
using MediatR;
using S.Archives.Api.Application.Command;
using S.Archives.Infrstructre.InterFace;

namespace S.Archives.Api.Application.CommandHandlers
{
    /// <summary>
    /// 修改档案类型,用于转种撤销
    /// </summary>
    public class SheepFileEditCommandHandler : IRequestHandler<SheepFileEditCommand, bool>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private readonly IMapper mapper;
        public SheepFileEditCommandHandler(ISheepFileRepository sheepFileRepository, IMapper mapper)
        {
            this.sheepFileRepository = sheepFileRepository;
            this.mapper = mapper;
        }

        public async Task<bool> Handle(SheepFileEditCommand request, CancellationToken cancellationToken)
        {
            var sheep= sheepFileRepository.GetAll().FirstOrDefault(x=>x.EarTag==request.EarTag);
            sheep.FileType = 3;
            return sheepFileRepository.Update(sheep);
        }
    }
}
